/*
练习引用，应用和原来对象的地址是一样的，也就是说引用的直接使用的话相当于 值，&引用 可以获取应用的地址
prats:101
r_pats:101
rats: 101 rodents: 101
rats: 102 rodents: 102
rats address: 0x7ff7be168578 rodents address: 0x7ff7be168578
*/
#include <iostream>
void swapr(int & a, int & b);

int main_first_ref()
{
    using namespace std;
    int rats = 101;
    int *p_rats = &rats;
    int &r_rats = *p_rats;
    cout << "prats:" << *p_rats << endl;
    cout << "prats:address:" << p_rats << endl;
    cout << "r_pats:" << r_rats << endl;

    // 引用可以直接使用值初始化，其地址还是和值的的地址一样的
    int & rodents = rats;
    cout << "rats: " << rats << " rodents: " << rodents << endl;
    rodents ++;
    cout << "rats: " << rats << " rodents: " << rodents << endl;
    cout << "rats address: " << &rats << " rodents address: " << &rodents << endl;
    return 0;
}

void swapr(int & a, int & b)
{
    int temp;
    temp = a;
    a = b;
    b = temp;
}
